package com.fyt.ZhongYaoApp.Controller;

import com.fyt.ZhongYaoApp.pojo.Hospital;
import com.fyt.ZhongYaoApp.pojo.PageBean;
import com.fyt.ZhongYaoApp.pojo.Result;
import com.fyt.ZhongYaoApp.pojo.pg.HospitalPG;
import com.fyt.ZhongYaoApp.pojo.vo.HospitalVO;
import com.fyt.ZhongYaoApp.service.HospitalService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/hospital")
@Tag(name = "hospital",description = "the hospital API") // 接口大标题
public class HospitalController {

    @Autowired
    private HospitalService hospitalService;

    @PostMapping("/add")
    public Result add(@RequestBody Hospital hospital) {

        hospitalService.add(hospital);
        return Result.success("医院添加成功");
    }

    /**
     * 查看医院列表
     * @return
     */
    @GetMapping("/list")
    public Result<List<Hospital>> hospitalList() {

        List<Hospital> list = hospitalService.hospitalList();
        return Result.success(list);
    }

    /**
     * 根据id获取医院名称
     * @param hospital
     * @return
     */
    @GetMapping("/getName")
    public Result<String> getName(@RequestBody Hospital hospital) {

        return Result.success(hospitalService.getNameById(hospital));
    }

    /**
     * 根据医院名称模糊查询医院信息
     * @param hospitalPG
     * @return
     */
    @GetMapping("/querryHospital")
    public Result<PageBean<HospitalVO>> querryHospital(@RequestBody HospitalPG hospitalPG) {

        return Result.success(hospitalService.querryHospital(hospitalPG));
    }

    /**
     * 根据id返回医院详情
     * @param hospital
     * @return
     */
    @GetMapping("/querryHospitalById")
    private Result<Hospital> queryHospitalById(@RequestBody Hospital hospital) {

        return Result.success(hospitalService.querryHospitalById(hospital));
    }


}
